/*
    This file is part of FISCO-BCOS.

    FISCO-BCOS is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    FISCO-BCOS is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with FISCO-BCOS.  If not, see <http://www.gnu.org/licenses/>.
*/
/** @file CryptoPP.h
 * @author Alex Leverington <nessence@gmail.com> Asherli
 * @date 2018
 *
 * CryptoPP headers and primitive helper methods
 */

#pragma once

#include "Common.h"

namespace dev
{
namespace crypto
{
/// Amount of bytes added when encrypting with encryptECIES.
static const unsigned c_eciesOverhead = 113;

/**
 * CryptoPP secp256k1 algorithms.
 * @todo Collect ECIES methods into class.
 */
class Secp256k1PP
{
public:
    static Secp256k1PP* get();

    /// Encrypts text (replace input). (ECIES w/XOR-SHA1)
    void encrypt(Public const& _k, bytes& io_cipher);

    /// Decrypts text (replace input). (ECIES w/XOR-SHA1)
    void decrypt(Secret const& _k, bytes& io_text);

    /// Encrypts text (replace input). (ECIES w/AES128-CTR-SHA256)
    void encryptECIES(Public const& _k, bytes& io_cipher);

    /// Encrypts text (replace input). (ECIES w/AES128-CTR-SHA256)
    void encryptECIES(Public const& _k, bytesConstRef _sharedMacData, bytes& io_cipher);

    /// Decrypts text (replace input). (ECIES w/AES128-CTR-SHA256)
    bool decryptECIES(Secret const& _k, bytes& io_text);

    /// Decrypts text (replace input). (ECIES w/AES128-CTR-SHA256)
    bool decryptECIES(Secret const& _k, bytesConstRef _sharedMacData, bytes& io_text);

    bool agree(Secret const& _s, Public const& _r, Secret& o_s);

private:
    Secp256k1PP() = default;
};

}  // namespace crypto
}  // namespace dev
